﻿using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;

namespace WT.OpenIddict.Repository.Services;

public interface IRepository<TEntity, TKey> where TEntity : class where TKey : new()
{
    Task<IQueryable<TEntity>> GetQueryableAsync(bool isOpenSoftDeleteFilter = true);

    Task<TEntity> InsertAsync(TEntity entity, bool isAutoSave = true);

    Task InsertManyAsync(IQueryable<TEntity> entities, bool isAutoSave = true);

    Task InsertManyAsync(List<TEntity> entities, bool isAutoSave = true);

    Task<TEntity> UpdateAsync(TEntity entity, bool isAutoSave = true);

    Task UpdateManyAsync(IQueryable<TEntity> entities, bool isAutoSave = true);
    Task UpdateManyAsync(List<TEntity> entities, bool isAutoSave = true);

    Task DeleteAsync(TKey id, bool isSoftDelete = true, bool isAutoSave = true);

    Task DeleteAsync(TEntity entity, bool isSoftDelete = true, bool isAutoSave = true);

    Task<TEntity> FindAsync(TKey id, bool isOpenSoftDeleteFilter = true);

    Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> predicate, bool isOpenSoftDeleteFilter = true);
    Task DeleteManyAsync(IQueryable<TEntity> deleteEntitys, bool isSoftDelete = true, bool isAutoSave = true);
    Task DeleteManyAsync(List<TEntity> deleteEntitys, bool isSoftDelete = true, bool isAutoSave = true);

    Task<bool> AnyAsync(Func<TEntity, bool> predicate, bool isOpenSoftDeleteFilter = true);

    DbSet<TEntity> GetDbSet();
}